import BaseUtil from '@/BaseUtil';
import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import MathUtil from '@/MathUtil';
import RandomUtil from '@/RandomUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import VestCommon from 'code/Core/Common/VestCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 暗影漩涡
 **/
export default class SS_DarkWortex extends AbilityBase {
    static instance: SS_DarkWortex;
    buffType: AppBuffType = {
        id: 'buff_SS_DarkWortex',
        art: this.art,
        name: this.abilityName,
        ubertip: '',
        dur: 6,
        interval: 1,
        onInterval: this.onBuffInterval.bind(this),
        onDestroy: this.onEnd.bind(this),
    };
    onEnd(buff: Buff) {
        VestCommon.returnVest(buff.getParent());
    }
    onBuffInterval(buff: Buff) {
        let source = buff.getCaster();
        let v = buff.getParent();
        let es = SelectUtil.getEnemyUnitsInRange(v, 450);
        if (es.length == 0) return;
        for (let e of es) {
            let angle = MathUtil.angleBetweenCoords(GetUnitX(e), GetUnitY(e), GetUnitX(v), GetUnitY(v));
            let dis = MathUtil.distanceBetweenUnits(v, e);
            let lv = this.getAbilityLevel(source);
            let dmg = 35 * lv + UnitCommon.取法强(source) * (0.5 + 0.5 * lv);
            DamageSystemInstance.applyDarkDamage(e, source, dmg, this.id);
            MovementCommon.hitFly({
                target: e,
                caster: source,
                distance: dis > 200 ? 200 : dis,
                time: dis / 400,
                maxHeight: 0,
                angle,
            });
        }
    }
    constructor(id: string = 'Aayw') {
        super(id);
        SS_DarkWortex.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let v = VestCommon.getNoneModelVest(tarX, tarY, RandomUtil.randomAngle());
        SetUnitOwner(v, GetOwningPlayer(source), false);
        DzSetUnitModel(v, 'HellHole.mdx');
        BuffCommon.addBuff({ target: v, caster: source, ablityId: this.id, buffTypeId: this.buffType.id });
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
